package com.situ.student.service.impl;

import java.awt.Insets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.jar.Attributes.Name;

import com.situ.student.dao.IStudentDao;
import com.situ.student.dao.impl.StudentDaoJdbcImpl;
import com.situ.student.dao.impl.StudentDaoMemoryImpl;
import com.situ.student.entity.Student;
import com.situ.student.service.IStudentService;

public class StudentServiceImpl<Studnet> implements IStudentService{
//	private IStudentDao studentDao = new StudentDaoMemoryImpl();
	private IStudentDao studentDao = new StudentDaoJdbcImpl();
	/**
	 * 插入
	 */
	@Override
	public boolean insert(Student student) {
	int count  = studentDao.insert(student);//返回count，值为1，插入成功
	return count == 1 ? true : false;
		
	}
	/**
	 * 遍历，打印时更改
	 */
	@Override
	public List<Student> list() {
		List<Student> list = studentDao.list();
		List<Student> copyList = new ArrayList<>();
		for (Student student : list) {
			student.setName("Java1807" + student.getName());
			copyList.add(student);
		}
		return copyList;
		//return studentDao.list();
	}
	
	/**
	 * 删除
	 */
	@Override
	public boolean deleteById(Integer id) {
		int count = studentDao.deleteById(id);
		return count == 1 ? true : false;
	}
	
	/**
	 * 根据姓名查找
	 */
	@Override
	public List<Student> findByName(String name) {
		List<Student> list = studentDao.list();
		List<Student> copeList = new ArrayList<Student>();
		for (Student student : copeList) {
			copeList.add(student);
	} 
		return copeList;
	}
	
	
	
}	
